package engine

import (
	"fmt"
	"strings"
)

type SimpleEngine struct {}

func (e *SimpleEngine) Run(queue ...Request) {
	var count = 0
	for len(queue) > 0 {
		r := queue[0]
		queue = queue[1:]

		results,err := Worker(r)
		if err != nil {
			return
		}
		for _,r := range results.Requests {
			if strings.Index(r.Url,"http") == -1{
				r.Url = "http://m.mamicode.com" + r.Url
			}
			if IsDuplicate(r.Url) {
				continue
			}
			queue = append(queue,r)
		}
		for _,item := range results.Items {
			count++
			fmt.Printf("Got Item:$%d %v",count,item)
		}
	}
}